package oj;

import java.util.Stack;

public class Day7S {
    public boolean chkParenthesis(String A, int n) {
        if(n==0){
            return true;
        }
        if(n%2!=0){
            return false;
        }
        char[] arr=A.toCharArray();
        Stack<Character> stack=new Stack<>();
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]=='('){
                stack.push(arr[i]);
            }else if (arr[i]==')'){
                if(stack.isEmpty()){
                    return false;
                }else {
                    char c = stack.pop();
                    if (c != '(') {
                        return false;
                    }
                }
            }else {
                return false;
            }
        }
        return true;
    }
}
